﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Dami;

public partial class admin_Modules_detailPro_AddNew : System.Web.UI.UserControl
{
    protected void Page_Load(object sender, EventArgs e)
    {
        this.btnAddNew.Attributes.Add("onclick", "return OnSubmitClick();");
        this.btnCancel.Attributes.Add("onclick","return ClearAll()");

        if (!this.IsPostBack) {
            ViewState["URLReferrer"] = Request.UrlReferrer.AbsoluteUri;
            LoadCombobox();
        }
    }

    private void LoadCombobox() {
        WebData db = new WebData();
        this.cbbidProduct.DataSource = db.tbl_Products.GetAll();
        this.cbbidProduct.DataBind();
    }

    private void AddNew() {
        String strMess = "";
        int id = 0;
            try
            {
                
                WebData db = new WebData();
                DataLibrary.tbl_DetailProduct item = new DataLibrary.tbl_DetailProduct();
                item.Description = txtDescription.Text;
                item.Id = 1;
                item.IdProduct =Convert.ToInt32(cbbidProduct.SelectedValue);
                item.Description = txtDescription.Text;
                item.OrderId = Convert.ToInt32(txtorderId.Text);
                item.Name = txtname.Text;
                item.IsActive = 1;
                id=db.tbl_DetailProducts.InsertOnSubmit(item);
                
            }
            catch (Exception err)
            {
                strMess = Message.Insert_err + "! vì lỗi " + err.Message.ToString();
            }
            ScriptManager.RegisterStartupScript(this, this.GetType(), "Err", "alert('" + strMess + "');", true);
          if(id>0)
               Response.Redirect(ViewState["URLReferrer"].ToString());

    }

    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        AddNew();
    }

}